home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / MidMoose2 / MidMoose.c < prev    next >
C/C++ Source or Header  |  1995-07-30  |  6KB  |  201 lines

  1. #include "gst.c"
  2.  
  3. extern struct Library *CxBase = NULL;
  4. extern struct Library *IconBase = NULL;
  5.  
  6. #define VERSION "2.1"
  7. #define DEF_DOWNKEY "rawkey lcommand z"
  8. #define DEF_UPKEY "rawkey lcommand upstroke z"
  9. #define DEF_RDOWNKEY "rawkey lcommand repeat z"
  10. #define DEF_CXPRI 0
  11. #define PREFS_DOWNKEY prefs.downkey
  12. #define PREFS_UPKEY prefs.upkey
  13. #define PREFS_RDOWNKEY prefs.rdownkey
  14. #define PREFS_CXPRI prefs.cxpri
  15.  
  16. struct Prefs {
  17.     STRPTR downkey;
  18.     STRPTR upkey;
  19.     STRPTR rdownkey;
  20.     LONG   cxpri;
  21. };
  22.  
  23. struct Prefs prefs = {DEF_DOWNKEY, DEF_UPKEY, DEF_RDOWNKEY, DEF_CXPRI};
  24.  
  25. struct NewBroker newbroker = {
  26.     NB_VERSION,
  27.     "MidMoose",
  28.     "MidMoose "VERSION" ©1994-95 Lee Kindness",
  29.     "Middle mouse button emulation.",
  30.     NBU_UNIQUE | NBU_NOTIFY,
  31.     0, 127, 0, 0
  32. };
  33.  
  34. char vertag[] = "$VER: MidMoose "VERSION" "__AMIGADATE__;
  35.  
  36. int main(int argc, char **argv)
  37. {
  38.     /* open libraries */
  39.     if( (CxBase = OpenLibrary("commodities.library", 36)) &&
  40.         (IconBase = OpenLibrary("icon.library", 36)) )
  41.     {
  42.         /* create a message port */
  43.         if( newbroker.nb_Port = CreateMsgPort() )
  44.         {
  45.             CxObj *broker;
  46.             struct RDArgs *rdargs = NULL;
  47.             struct DiskObject *dobj = NULL;
  48.             
  49.             /* Get tooltypes */
  50.             if (argc ? FALSE : TRUE) {
  51.                 BPTR oldcd;
  52.                 struct WBStartup *wbs;
  53.                 #define PROGNAME wbs->sm_ArgList->wa_Name
  54.                 #define PDIRLOCK wbs->sm_ArgList->wa_Lock
  55.                 wbs = (struct WBStartup *)argv;
  56.                 /* Run from WB */
  57.                 oldcd = CurrentDir(PDIRLOCK);
  58.                 if (dobj = GetDiskObject(PROGNAME)) {
  59.                     STRPTR s;
  60.                     PREFS_DOWNKEY = FindToolType(dobj->do_ToolTypes, "UPKEY");
  61.                     PREFS_UPKEY = FindToolType(dobj->do_ToolTypes, "DOWNKEY");
  62.                     PREFS_RDOWNKEY = FindToolType(dobj->do_ToolTypes, "RDOWNKEY");
  63.                     if( s = FindToolType(dobj->do_ToolTypes, "CX_PRIORITY") )
  64.                         StrToLong(s, &PREFS_CXPRI);
  65.                 }
  66.                 CurrentDir(oldcd);
  67.             } else {
  68.                 #define OPT_UPKEY 0
  69.                 #define OPT_DOWNKEY 1
  70.                 #define OPT_RDOWNKEY 2
  71.                 #define OPT_CXPRI 3
  72.                 LONG args[4] = {0, 0, 0, 0};
  73.                 #define TEMPLATE "UPKEY/K,DOWNKEY/K,RDOWNKEY/K,CX_PRIORITY/K/N"
  74.                 /* Run from Shell */
  75.                 if (rdargs = ReadArgs(TEMPLATE, (LONG *)&args, NULL)) {
  76.                     if (args[OPT_UPKEY]) {
  77.                         PREFS_UPKEY = (STRPTR)args[OPT_UPKEY];
  78.                     }
  79.                     if (args[OPT_DOWNKEY]) {
  80.                         PREFS_DOWNKEY = (STRPTR)args[OPT_DOWNKEY];
  81.                     }
  82.                     if (args[OPT_RDOWNKEY]) {
  83.                         PREFS_RDOWNKEY = (STRPTR)args[OPT_RDOWNKEY];
  84.                     }
  85.                     if( args[OPT_CXPRI] ) 
  86.                         PREFS_CXPRI = *((LONG *)args[OPT_CXPRI]);
  87.                 }
  88.             }
  89.             if( PREFS_CXPRI > 127 )
  90.                 PREFS_CXPRI = 127;
  91.             if( PREFS_CXPRI < -128 )
  92.                 PREFS_CXPRI = -128;
  93.             
  94.             newbroker.nb_Pri = PREFS_CXPRI;
  95.         
  96.             /* create a CX broker */
  97.             if( broker = CxBroker(&newbroker, NULL) )
  98.             {
  99.                 CxObj *DownFilter, *UpFilter, *RDownFilter;
  100.                 /* create 2 filters */
  101.                 if( (DownFilter = CxFilter(PREFS_DOWNKEY)) && 
  102.                     (UpFilter = CxFilter(PREFS_UPKEY)) &&
  103.                     (RDownFilter = CxFilter(PREFS_RDOWNKEY)) )
  104.                 {
  105.                     struct InputEvent *Downie, *Upie;
  106.                     /* Add the filters to the brokwrs list */
  107.                     AttachCxObj(broker, DownFilter);
  108.                     AttachCxObj(broker, UpFilter);
  109.                     AttachCxObj(broker, RDownFilter);
  110.                     
  111.                     /* Alloc the translation input events */
  112.                     if( (Downie = AllocVec(sizeof(struct InputEvent), MEMF_CLEAR)) && 
  113.                         (Upie = AllocVec(sizeof(struct InputEvent), MEMF_CLEAR)) )
  114.                     {
  115.                         CxObj *DownTrans, *UpTrans, *RDownTrans;
  116.                         /* init. the translation input events */
  117.                         Downie->ie_Class = IECLASS_RAWMOUSE;
  118.                         Downie->ie_Code = IECODE_MBUTTON;
  119.                         Downie->ie_Qualifier = IEQUALIFIER_MIDBUTTON;
  120.                         Upie->ie_Class = IECLASS_RAWMOUSE;
  121.                         Upie->ie_Code = IECODE_MBUTTON | IECODE_UP_PREFIX;
  122.                     
  123.                         /* create translators */
  124.                         if( (DownTrans = CxTranslate(Downie)) && 
  125.                             (UpTrans = CxTranslate(Upie)) &&
  126.                             (RDownTrans = CxTranslate(NULL)) )
  127.                         {
  128.                             /* attach the translators to the filters */
  129.                             AttachCxObj(DownFilter, DownTrans);
  130.                             AttachCxObj(UpFilter, UpTrans);
  131.                             AttachCxObj(RDownFilter, RDownTrans);
  132.                             
  133.                             /* check for errors */
  134.                             if( (!CxObjError(DownFilter)) &&
  135.                                 (!CxObjError(UpFilter)) &&
  136.                                 (!CxObjError(RDownFilter)) )
  137.                             {
  138.                                 CxMsg *msg;
  139.                                 ULONG sigrcvd, msgid, msgtype, cxsigflag;
  140.                                 BOOL cont = TRUE;
  141.                                 /* turn on the broker */
  142.                                 ActivateCxObj(broker, 1L);
  143.                                 
  144.                                 cxsigflag = 1L << newbroker.nb_Port->mp_SigBit;
  145.                                 
  146.                                 /* process messages */
  147.                                 while(cont)
  148.                                 {
  149.                                     sigrcvd = Wait(SIGBREAKF_CTRL_C | cxsigflag);
  150.                                     while( msg = (CxMsg *)GetMsg(newbroker.nb_Port) )
  151.                                     {
  152.                                         msgid = CxMsgID(msg);
  153.                                         msgtype = CxMsgType(msg);
  154.                                         ReplyMsg((struct Message *)msg);
  155.                                         if( msgtype == CXM_COMMAND )
  156.                                         {
  157.                                             switch(msgid)
  158.                                             {
  159.                                                 case CXCMD_DISABLE:
  160.                                                     ActivateCxObj(broker, 0L);
  161.                                                     break;
  162.                                                 case CXCMD_ENABLE:
  163.                                                     ActivateCxObj(broker, 1L);
  164.                                                     break;
  165.                                                 case CXCMD_KILL:
  166.                                                     cont = FALSE;
  167.                                                     break;
  168.                                                 case CXCMD_UNIQUE:
  169.                                                     cont = FALSE;
  170.                                                     break;
  171.                                             }
  172.                                         }
  173.                                     }
  174.                                     if( sigrcvd & SIGBREAKF_CTRL_C )
  175.                                         cont = FALSE;
  176.                                 }
  177.                             }
  178.                         }
  179.                         /* free the translation input events */
  180.                         FreeVec(Upie);
  181.                         FreeVec(Downie);
  182.                     }
  183.                 }
  184.                 /* free the broker */
  185.                 DeleteCxObjAll(broker);
  186.             }
  187.             /* Free dobj/rdargs */
  188.             if( dobj )
  189.                 FreeDiskObject(dobj);
  190.             if( rdargs )
  191.                 FreeArgs(rdargs);
  192.  
  193.             /* free the port */
  194.             DeletePort(newbroker.nb_Port);
  195.         }
  196.         /* close libraries */
  197.         CloseLibrary(IconBase);
  198.         CloseLibrary(CxBase);
  199.     }
  200.     return 0;
  201. }